package com.System.LearnSystem;

public class Result<T>
{
	    /** 响应码 */
	    private Integer code;
	    /** 响应消息 */
	    private String message;
	    /** 响应数据 */
	    private T data;
	    /** 响应时间戳 */
	    private static Long timestamp;
	    
	    /** 成功响应码 */
	    public static final Integer SUCCESS = 200;
	    /** 参数错误响应码 */
	    public static final Integer PARAM_ERROR = 400;
	    /** 未授权响应码 */
	    public static final Integer UNAUTHORIZED = 401;
	    /** 禁止访问响应码 */
	    public static final Integer FORBIDDEN = 403;
	    /** 资源不存在响应码 */
	    public static final Integer NOT_FOUND = 404;
	    /** 服务器错误响应码 */
	    public static final Integer ERROR = 500;

	    /**
	     * 私有构造方法
	     */
	    public Result() {
	        this.timestamp = System.currentTimeMillis();
	    }  
	    
	    private void setCode(Integer code)
	    {
			this.code = code;
		}
	    public Integer getCode()
	    {
	    	return code;
	    }
	    
	    public void setMessage(String string)
	    {
			this.message = string;
			
		}	    
	    public String getMessage()
	    {
	    	return message;
	    }
	    
	    private void setData(T data) 
	    {
			this.data = data;
		}
	    public  T getDate()
	    {
	    	return data;
	    }
	    
	    public Long gettimetamp()
	    {
	    	return timestamp;
	    }
	    /**
	     * 成功响应
	     */
	    public static <T> Result<T> success() {
	        Result<T> result = new Result<>();
	        result.setCode(SUCCESS);
	        result.setMessage("操作成功");
	        timestamp = System.currentTimeMillis();
	        return result;
	    }
	 
		/**
	     * 成功响应
	     * @param data 响应数据
	     */
	    public static <T> Result<T> success(T data) {
	        Result<T> result = new Result<>();
	        result.setCode(SUCCESS);
	        result.setMessage("操作成功");
	        result.setData(data);
	        timestamp = System.currentTimeMillis();
	        return result;
	    }
	
		/**
	     * 失败响应
	     * @param code 错误码
	     * @param message 错误信息
	     */
	    public static <T> Result<T> error(Integer code, String message) {
	        Result<T> result = new Result<>();
	        result.setCode(code);
	        result.setMessage(message);
	        timestamp = System.currentTimeMillis();
	        return result;
	    }
}


